package com.xbs.controller.content;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.service.content.PayService;
/**
 * 支付页面servlet
 * @author 余凯
 *
 */
@WebServlet("/content/pay")
public class PayServlet extends BaseServlet{
	private PayService ps;
	
	public PayServlet() {
		ps = new PayService();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		forward("businessview/xw_order/pay");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String zhifu = req.getParameter("zhifu");
		if(zhifu.equals("支付成功")){
			//获取订单编号
			String ordernum = req.getParameter("ordernum");
			//获取第一次实付的金额
			Double money = Double.parseDouble(req.getParameter("mon"));
			//更新订单表的第一次实收金额
			ps.upFirstMoney(ordernum, money);
			//更新该订单表的实收金额
			ps.upFactMoney(ordernum, money);
			//更改订单的状态
			ps.upStatus(ordernum,"预定成功");
			//获取支付全款的时间
			Date now = new Date();
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String date = df.format(now);
			Timestamp ts = new Timestamp(System.currentTimeMillis());
			ts = Timestamp.valueOf(date);
			//插入操作时间表的订单付款时间
			ps.upOrderPay(ordernum, ts);
		}
		System.out.println("fdl");
		redirect("/mycenter");
	}

}
